package uk.co.agileworks.bidpirate.model;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.jasypt.hibernate.type.EncryptedStringType;

@TypeDef(name = "encryptedString", typeClass = EncryptedStringType.class, parameters = { @Parameter(name = "encryptorRegisteredName", value = "strongHibernateStringEncryptor") })
@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = "USERNAME"))
public final class User implements Serializable {

	private static final long serialVersionUID = 1L;
	private static final String HIDDEN_FIELD = "password";

	@Id
	@GeneratedValue
	private Long id;
	private String username;
	@Type(type = "encryptedString")
	private String password;
	@Transient
	private Region region;

	public Long getId() {
		return id;
	}

	public String getPassword() {
		return password;
	}

	public Region getRegion() {
		return region;
	}

	public String getUsername() {
		return username;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setRegion(Region region) {
		this.region = region;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Override
	public String toString() {
		return ReflectionToStringBuilder.toStringExclude(this, HIDDEN_FIELD);
	}

}
